/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package br.gov.cemaden.library.dao.smp;

import br.gov.cemaden.library.dao.GenericDao;
import br.gov.cemaden.library.interfaces.smp.LogAplicacaoInterface;
import br.gov.cemaden.library.model.smp.LogAplicacao;
import br.gov.cemaden.library.model.staff.Aplicacao;
import java.util.List;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

/**
 *
 * @author alan
 */
public class LogAplicacaoDao extends GenericDao implements LogAplicacaoInterface{
    
    Session session;
    
    public LogAplicacaoDao(Session session){
        this.session = session;
    }
    
    public List<LogAplicacao> findAll() {
        List<LogAplicacao> list = null;
        try{
            Query query = session.getNamedQuery("LogAplicacao.findAll");
            list = query.list();
        }
        catch(HibernateException ex){
            throw ex;
        }
        return list;
    }

    public List<LogAplicacao> findByAplicacao(Aplicacao aplicacao) {
        List<LogAplicacao> list = null;
        try{
            Query query = session.getNamedQuery("LogAplicacao.findByAplicacao").setParameter("aplicacao", aplicacao);
            list = query.list();
        }
        catch(HibernateException ex){
            throw ex;
        }
        return list;
    }

    public void insert(LogAplicacao log){
        
        try{
            saveOrUpdate(session, log);
        }catch(Exception ex){
            throw new HibernateException(ex);
        }
    }
    
}
